//
//  WSPurchaseFooterView.m
//  BaseProject
//
//  Created by karong on 2023/7/24.
//

#import "WSPurchaseFooterView.h"

@interface WSPurchaseFooterView ()

@property (weak, nonatomic) IBOutlet UIButton *feedbackBtn;
@property (weak, nonatomic) IBOutlet YYLabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *subLabel;

@end

@implementation WSPurchaseFooterView

- (void)awakeFromNib {
    [super awakeFromNib];
    self.titleLabel.attributedText = [self purchaseTitle];
//    self.subLabel.attributedText = [WSPurchaseFooterView purchaseText];
}

- (NSMutableAttributedString *)purchaseTitle {
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    style.alignment = NSTextAlignmentLeft;
    style.lineBreakMode = NSLineBreakByWordWrapping;
    NSString *text = @"1、开通会员的用户可以观看有VIP标签的剧集，在该剧集下不再额外扣除剧豆 。账户余额剧豆 将在会员到期后继续使用\n2、单独的剧豆可用于在本产品内解锁付费剧集。未满18岁的用户不支持购买，剧豆为虚拟商品不支持无理由退款\n3、购买前请阅读《会员服务协议》（内含退订方式以及剧豆使用规则）\n4、如果碰到任何问题，请在我的页面联系我们或者给我们留言，我们会尽快与您联系";
    NSMutableAttributedString *attrText = [[NSMutableAttributedString alloc] initWithString:text
                                                                                 attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12], NSParagraphStyleAttributeName: style, NSForegroundColorAttributeName: UIColor.font_white_ffffff}];
    WeakSelf
    NSString *string1 = @"《會員服務協議》";
    NSRange range1 = [text rangeOfString:string1];
    [attrText addAttributes:@{NSUnderlineStyleAttributeName: @(1)} range:range1];
    [attrText setTextHighlightRange:range1 color:UIColor.font_yellow_FCB625 backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        if ([weakSelf.delegate respondsToSelector:@selector(purchaseFooterViewWebActionWithUrl:titleStr:)]) {
            [weakSelf.delegate purchaseFooterViewWebActionWithUrl:API_CHARONTV_AGREEMENT_VIP titleStr:@"會員服務協議"];
        }
    }];
    
//    NSString *string2 = @"《自動續費付費規則》";
//    NSRange range2 = [text rangeOfString:string2];
//    [attrText addAttributes:@{NSUnderlineStyleAttributeName: @(1)} range:range2];
//    [attrText setTextHighlightRange:range2 color:UIColor.font_yellow_FCB625 backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
//        if ([weakSelf.delegate respondsToSelector:@selector(purchaseFooterViewWebActionWithUrl:titleStr:)]) {
//            [weakSelf.delegate purchaseFooterViewWebActionWithUrl:API_AGREEMENT_VIP_RENWAL titleStr:@"自動續費付費規則"];
//        }
//    }];
    return attrText;
}

+ (NSMutableAttributedString *)purchaseText {
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    style.alignment = NSTextAlignmentLeft;
    style.lineBreakMode = NSLineBreakByWordWrapping;
    NSString *text = @"1、开通会员的用户可以观看有VIP标签的剧集，在该剧集下不再额外扣除剧豆 。账户余额剧豆 将在会员到期后继续使用\n2、单独的Coins可用于在本产品内解锁付费剧集。未满18岁的用户不支持购买，剧豆为虚拟商品不支持无理由退款\n3、购买前请阅读《会员服务协议》（内含退订方式以及剧豆使用规则）\n4、如果碰到任何问题，请在我的页面联系我们或者给我们留言，我们会尽快与您联系";
    NSMutableAttributedString *attrText = [[NSMutableAttributedString alloc] initWithString:text
                                                                                 attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12], NSParagraphStyleAttributeName: style, NSForegroundColorAttributeName: UIColor.font_white_ffffff}];
    return attrText;
}

+ (CGFloat)cellHeight {
    CGFloat height = [[self purchaseText] boundingRectWithSize:CGSizeMake(WSScreenWidth - 31, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size.height;
    return  height;
}

@end
